﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;
using System.ServiceModel;
using Cesave.DistributedServices.Core.ErrorHandlers;
using Cesave.Domain.PermisosModule.Contracts.Cultivos;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cultivo"></param>
		public void AddCultivo(Domain.PermisosModule.Entities.Cultivo cultivo)
		{
			try
			{
				ICultivoService cultivoService = IoCFactory.Resolve<ICultivoService>();
				cultivoService.AddCultivo(cultivo);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cultivo"></param>
		public void ChangeCultivo(Domain.PermisosModule.Entities.Cultivo cultivo)
		{
			try
			{
				ICultivoService cultivoService = IoCFactory.Resolve<ICultivoService>();
				cultivoService.ChangeCultivo(cultivo);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.Cultivo> FindAllCultivos()
		{
			try
			{
				ICultivoService cultivoService = IoCFactory.Resolve<ICultivoService>();
				return cultivoService.FindAllCultivos();
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="status"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.Cultivo> FindCultivosByStatus(bool status = true)
		{
			try
			{
				ICultivoService cultivoService = IoCFactory.Resolve<ICultivoService>();
				return cultivoService.FindCultivosByStatus(status);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cicloGuid"></param>
		/// <param name="juntaGuid"></param>
		/// <param name="fromDate"></param>
		/// <param name="toDate"></param>
		/// <param name="status"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.Cultivo> FindCultivosForExpedicion(Guid cicloGuid, Guid juntaGuid, DateTime fromDate, DateTime toDate, bool status = true)
		{
			try
			{
				ICultivoService cultivoService = IoCFactory.Resolve<ICultivoService>();
				return cultivoService.FindCultivosForExpedicion(
					cicloGuid,
					juntaGuid,
					fromDate,
					toDate,
					status
				);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		#endregion
	}
}
